package com.edu.gdkm.util;

import com.edu.gdkm.db.*;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class dbUtil {
    public Connection getConn() throws SQLException, ClassNotFoundException {
        // 链接地址、用户、密码
        String url = "jdbc:mysql://localhost:3306/dyp?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String pwd = "root";
        // 驱动加载
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection(url, user, pwd);
        return conn;
    }

    public void close(Connection conn, Statement stat, ResultSet result) throws SQLException {
        close(conn, stat);
        if (result != null) result.close();
    }

    public void close(Connection conn, Statement stat) throws SQLException {
        if (conn != null) conn.close();
        if (stat != null) stat.close();
    }
}
